home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BMUG PD-ROM B4
/
PD-ROM B4.iso
/
Entertainment
/
Strategy
/
Robots
/
bot 1.0.1
/
Tutorial
/
ASM
/
Middle
< prev
next >
Wrap
Text File
|
1991-06-25
|
6KB
|
286 lines
!
! Middle
!
! This bot uses a number of the more advanced design options,
! including intelligent damage recognition and a repair
! mechanism. It takes advantage of the fact that from the
! middle of the arena you are always scanning at a fairly close
! distance, so it's more likely that a given scan will find an
! enemy bot (Which means you want a very wide scan increment
! when scanning in a circle).
#DATA
EQU INCR 37
EQU FIND_INCR 11
DEF SCAN
DEF D
DEF DAMAGE_LOC
DEF TEMP
DEF CPUTHRESH
DEF FIRST_TIME
#CODE ASM
MOV A1, CPUTHRESH ! If CPU < 1/2 MAXCPU, then the repair
DIV 2, CPUTHRESH ! mechanism might jam. Therefore,
! don't use it to time movements.
MOV D0, D
JMP RUNAWAY_START ! Move to center
:START
MOV D0, D
RND 360, SCAN
:SCANLOOP
CMP D0, D
BNE GOT_HIT
ADD INCR, SCAN
SCN SCAN
CMP S0, 0
BEQ SCANLOOP
:SCANLOCK
MOV S1, R1
FIR 1
CMP D0, D
BNE GOT_HIT
SCN S1 ! Center the scanner on the enemy
CMP S0, 0
BNE SCANLOCK ! If we lost the lock, continue on
:LOCKON ! Try to locate the moving enemy
MOV SCAN, TEMP
SUB 43, TEMP
SCN TEMP
CMP S0, 0
BNE SCANLOCK
ADD FIND_INCR, TEMP
SCN TEMP
CMP S0, 0
BNE SCANLOCK
ADD FIND_INCR, TEMP
CMP D0, D ! In case we've been hit
BNE GOT_HIT
SCN TEMP
CMP S0, 0
BNE SCANLOCK
ADD FIND_INCR, TEMP
SCN TEMP
CMP S0, 0
BNE SCANLOCK
JMP SCANLOOP ! Couldn't find him.
! These routines are called if damage is taken while we're
! sitting in the center of the arena. Calls to the REPAIR
! mechanism are used to time the movement (and they repair the
! CPU if it gets damaged). The bot will basically make a loop
! and go back into the middle.
:GOT_HIT
VEL 220, 70 ! Start running immediately
MOV D2, DAMAGE_LOC
CMP A1, CPUTHRESH
BLT GOT_HIT2
RPR 0, 2 ! Repair System 0 (the CPU) for 20
VEL -70, -220
RPR 0, 2 ! Repair some more
MOV D0, D
JMP RUNAWAY_START
:GOT_HIT2 ! If CPU has been damaged
NOP
NOP ! If the repair mechanism jams due
NOP ! to the damaged CPU, we might keep
NOP ! repairing as we moved right into
NOP ! a wall! Don't take that chance.
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
VEL -40, -150
RPR 0, 2
VEL 0, 0
MOV D0, D
! Move to the center of the arena. If you get hit, go to the
! appropriate DAMAGE routine, below. This is the same basic
! movement routine used by the previous bots, except that it
! checks for damage.
:RUNAWAY_START
RND 360, R1
:RUNAWAY_X
CMP D0, D
BNE X_DAMAGE
:CONTINUE_X
MOV 128, TEMP
SUB X0, TEMP
MUL 4, TEMP
VEL TEMP, 0
FIR 1 ! Fire while moving. Why not?
CMP X0, 136 ! After all, you might hit someone.
BGT RUNAWAY_X
CMP X0, 120
BLT RUNAWAY_X
VEL 0, 0
:RUNAWAY_Y
CMP D0, D
BNE Y_DAMAGE
:CONTINUE_Y
MOV 128, TEMP
SUB Y0, TEMP
MUL 4, TEMP
VEL 0, TEMP
FIR 1
CMP Y0, 136
BGT RUNAWAY_Y
CMP Y0, 120
BLT RUNAWAY_Y
VEL 0, 0
ADD 1, FIRST_TIME
CMP FIRST_TIME, 1 ! Don't do the following routine
BEQ START ! the first time we move.
! Use the Damage Recognition System: The general direction of
! the shot that hit us is now stored in DAMAGE_LOC (it was in
! D2, but DAMAGE_LOC got a copy of it right after we started to
! run away). That value is accurate (roughly) within 45
! degrees. So, start scanning 45ish degrees less than that
! value and try to find your attacker.
MOV D0, D
RND 4, SCAN
ADD DAMAGE_LOC, SCAN
ADD 43, DAMAGE_LOC ! Go back to regular scanning if it
SUB 47, SCAN ! gets about 90 past the beginning
SUB FIND_INCR, SCAN ! (We add this right back (below))
:FIND_SCANLOOP
CMP SCAN, DAMAGE_LOC
BGT START
CMP D0, D
BNE GOT_HIT
ADD FIND_INCR, SCAN
SCN SCAN
CMP S0, 0
BEQ FIND_SCANLOOP
:FIND_SCANLOCK
MOV S1, R1
FIR 1
CMP D0, D
BNE GOT_HIT
SCN S1
CMP S0, 0
BNE FIND_SCANLOCK ! If we lost the lock, go back to
! scanning normally
JMP START
! These routines are called if the bot takes damage while
! moving to the center of the arena. They check to see if the
! damage was due to a collision (D1 == 4). If not, then don't
! worry about it, as the enemy probably can't lock on to a
! moving target too well. If so, then we bumped into someone.
! Scan for them and shoot if we find them.
:X_DAMAGE
MOV D0, D
CMP D1, 4
BNE CONTINUE_X
:X_TESTDIRECTION ! Damage was from a collision
CMP X0, 130
BLT X_LESSTHAN ! Are we moving left or right?
VEL 10, 0 ! (Back up slowly while firing)
MOV 150, SCAN
JMP X_SHOOT
:X_LESSTHAN
VEL -10, 0
MOV -30, SCAN
:X_SHOOT
SCN SCAN ! Scan 30 away from the x-axis
CMP S0, 0
BNE X_QUICKSHOT
ADD 60, SCAN
SCN SCAN ! Now scan 30 in the *other* direction
CMP S0, 0
BNE X_QUICKSHOT
SUB 30, SCAN
SCN SCAN ! Finally, scan right along the x-axis
CMP S0, 0
BNE X_QUICKSHOT
MOV D0, D
JMP CONTINUE_X
:X_FIREAT
SCN S1 ! Center the scanner on the enemy
CMP S0, 0
BNE X_QUICKSHOT
MOV D0, D
JMP CONTINUE_X
:X_QUICKSHOT
MOV S1, R1
FIR 1
JMP X_FIREAT
:Y_DAMAGE
MOV D0, D
CMP D1, 4
BNE CONTINUE_Y
:Y_TESTDIRECTION ! Damage was from a collision
CMP Y0, 130
BLT Y_LESSTHAN ! Are we moving up or down?
VEL 0, 10
MOV 240, SCAN
JMP Y_SHOOT
:Y_LESSTHAN
VEL 0, -10
MOV 60, SCAN
:Y_SHOOT
SCN SCAN ! Scan 30 away from the y-axis
CMP S0, 0
BNE Y_QUICKSHOT
ADD 60, SCAN
SCN SCAN ! Now scan 30 in the *other* direction
CMP S0, 0
BNE Y_QUICKSHOT
SUB 30, SCAN
SCN SCAN ! Finally, scan right along the y-axis
CMP S0, 0
BNE Y_QUICKSHOT
MOV D0, D
JMP CONTINUE_Y
:Y_FIREAT
SCN S1 ! Center the scanner on the enemy
CMP S0, 0
BNE Y_QUICKSHOT
MOV D0, D
JMP CONTINUE_Y
:Y_QUICKSHOT
MOV S1, R1
FIR 1
JMP Y_FIREAT
#END